<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSharesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up(): void
    {
        Schema::create('shares', function (Blueprint $table) {
            $table->Increments('id')->comment('internal ID');
            $table->string('external_id', 32)->default('')->comment('External ID');
            $table->string('business_type')->default(0)->comment('business type');
            $table->integer('business_id')->default(0)->comment('Business ID');
            $table->integer('organization_type_id')->default(0)->comment('organization type:11user、12subsidiary、13department、14location、15channel');
            $table->integer('organization_id')->comment('organization')->default(0);
            $table->integer('parent_subsidiary_id')->comment('parent subsidiary')->default(0)->index();
            $table->integer('origin_business_type_id')->default(0)->comment('origin type');
            $table->integer('origin_business_id')->default(0)->comment('origin ID');
            $table->integer('status_type_id')->default(0)->comment('status');
            $table->integer('user_id')->default(0)->comment('Business ID')->index('user_id');
            $table->integer('subsidiary_id')->default(0)->comment('subsidiary ID')->index();
            $table->integer('department_id')->default(0)->comment('department ID')->index();
            $table->integer('location_id')->default(0)->comment('location ID')->index();
            $table->integer('channel_id')->default(0)->comment('channel ID')->index();
            $table->integer('created_at')->default(0)->comment('created_at');
            $table->integer('updated_at')->default(0)->comment('updated_at');

            $table->index(['business_type', 'business_id'],'business_type');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down(): void
    {
        Schema::dropIfExists('shares');
    }
}
